package com.sensePlusVR.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.sensePlusVR.bean.GameItem;
import com.sensePlusVR.bean.PlayVideoParam;
import com.sensePlusVR.main.IntroFrameActivity;
import com.sensePlusVR.main.R;
import com.sensePlusVR.main.VrRealTestActivity;

import java.util.List;


public class PageJumpUtil {

	private static final String TAG = PageJumpUtil.class.getSimpleName();
	
	public static final String EntryPoint_KEY = "entryPoint";
	
	public static final String Entity_KEY = "entity";
	
	public static final String VRMode_KEY = "vrMode";
	
	public static final String GAME_ID_KEY = "gameId";
	
	public static final String FROMSETTING_KEY = "isFromSetting";
	
	public static final String VRVideo_KEY = "vrVIDEO";
	
	public static final String GamePara_KEY = "sexGamePara";
	
	public static final String RealConfig_KEY = "realConfig";
	
	
	
	//入口点
	public class EntryPoint{
		
	    public static final int EntryPoint_Game = 0;
	    public static final int EntryPoint_VideoPlane = 1;
	    public static final int EntryPoint_VideoPanor = 2;
	}
	
	public static void JumpToVRwithGame(Context ctx,Class<?> cls,boolean isVRMode,List<String> paths){
		
		Intent intent = new Intent(ctx,cls);
		
		Bundle bundle = new Bundle();
		
		bundle.putBoolean(VRMode_KEY, isVRMode);
		
		bundle.putInt(EntryPoint_KEY, EntryPoint.EntryPoint_Game);
		
		StringBuilder sb = new StringBuilder();
		
		
		for(String path:paths){
			
			MyLog.e(TAG, "PageJumpUtil url:"+path);
			
			sb.append(path).append(";");
		
		}
		
		
		bundle.putString(GamePara_KEY, sb.toString());
		
		intent.putExtras(bundle);
		
	
		ctx.startActivity(intent);
		
	
		
	}
	

	
	
	
	
	
	public static void JumpToVRwithPlaneVideo(Context ctx,Class<?> cls,int videoId,String title,String playUrl,int videoType){
		
		Intent intent = new Intent(ctx,cls);
	
		
		Bundle bundle = new Bundle();
		
		PlayVideoParam playVideoParam = new PlayVideoParam(videoId, title, playUrl, videoType);
		
	
		bundle.putBoolean(VRMode_KEY, true);
			
		bundle.putInt(EntryPoint_KEY, EntryPoint.EntryPoint_VideoPlane);
		
	
		bundle.putParcelable(Entity_KEY, playVideoParam);
		
		intent.putExtras(bundle);
		
	
		ctx.startActivity(intent);
		
	}
	
	public static void JumpToVRwithPanorVideo(Context ctx,Class<?> cls,int videoId,String title,String playUrl,int videoType){
		
		Intent intent = new Intent(ctx,cls);
		
		intent.putExtra("RETURN_2D_ACTIVITY_EXTRA",ctx.getClass().getName());
		
		Bundle bundle = new Bundle();
		
		PlayVideoParam playVideoParam = new PlayVideoParam(videoId, title, playUrl, videoType);
	
		bundle.putBoolean(VRMode_KEY, true);
		
		bundle.putInt(EntryPoint_KEY, EntryPoint.EntryPoint_VideoPanor);
		
		bundle.putParcelable(Entity_KEY, playVideoParam);
		
		intent.putExtras(bundle);
		
	
		ctx.startActivity(intent);
		
	}
	
	
	private static Class<?> cls1;
	private static boolean isVrMode1;
	private static List<String> paths1;
	private static GameItem gameItem1;
	
	/**
	 * 跳转真人视频
	 * @param ctx
	 * @param cls
	 * @param gameConfig
	 * @param isVrMode
	 */
	public static void JumpToRealGame(Context ctx,Class<?> cls,boolean isVrMode,List<String> paths,GameItem gameItem){
		cls1 = cls;
		isVrMode1 = isVrMode;
		paths1 = paths;
		gameItem1 = gameItem;
		
		if(isVrMode){
			ctx.startActivity(new Intent(ctx, IntroFrameActivity.class));
		}else{
			JumpToRealGame(ctx);
		}
		
	}
	
	public static void JumpToRealGame(Context context){
		
		StringBuilder sb = new StringBuilder();
		
		for(String path:paths1){
			
			sb.append(path).append(";");
		
		}
				
		
		Intent intent = new Intent(context,cls1);
		
		Bundle bundle = new Bundle();
		
		bundle.putBoolean(VRMode_KEY, isVrMode1);
		
		bundle.putInt(GAME_ID_KEY, gameItem1 == null?0:gameItem1.getId());
		
		
		bundle.putString(RealConfig_KEY, sb.toString());
		
		intent.putExtras(bundle);
		
		context.startActivity(intent);
		
		if(context instanceof Activity){
			((Activity)context).overridePendingTransition(R.anim.activity_alpha_in, R.anim.activity_alpha_out);	
		}
	}

	/**
	 * 跳转真人视频性能测试
	 * @param ctx
	 * @param cls
	 * @param isVrMode
	 * @param isVrVideo
	 */
	public static void JumpToRealGameForTest(Context ctx,boolean isVrMode,boolean isVrVideo,boolean isFromSetting){
		
		Intent intent = new Intent(ctx, VrRealTestActivity.class);
		
		Bundle bundle = new Bundle();
		
		bundle.putBoolean(VRMode_KEY, isVrMode);
		
		bundle.putBoolean(VRVideo_KEY, isVrVideo);
		
		bundle.putBoolean(FROMSETTING_KEY, isFromSetting);
		
		intent.putExtras(bundle);
		
	
		ctx.startActivity(intent);
		
	}	
	
}
